/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_DEC_DEBLOCKER_H
#define __UMC_AVS_DEC_DEBLOCKER_H

#include "ippdefs.h"
#include "ippvc.h"
#include "umc_avs_context.h"

namespace UMC
{

// forward declaration of used types
struct AVS_MB_INFO;

class AVSDeblocker
{
public:

    enum
    {
        VerticalEdge = 0,
        HorizontalEdge = 1
    };

    // Default constructor
    AVSDeblocker(void);
    // Destructor
    virtual
    ~AVSDeblocker(void);

    //
    // Initialization functions
    //

    // Set decoding parameters
    inline
    void SetDeblockingContext(AVS_DEBLOCKING_CONTEXT &decCtx);
    // Get deblocking parameters
    inline
    AVS_DEBLOCKING_CONTEXT & GetDeblockingContext(void);
    // Set decoding decoding parameters

    //
    // Deblocking functions
    //
    void DeblockIMacroBlocksRow(void);
    void DeblockPMacroBlocksRow(void);
    void DeblockBMacroBlocksRow(void);

protected:

    // Prepare pointers to neighbours macroblock info
    void PrepareNeighbours(AVS_BASE_CONTEXT *pCtx);
    // Prepare deblocking variables
    void PrepareDeblocking(void);

    // Advance pointers to neighbours macroblocks
    void AdvanceNeighbours(void);
    // Update decoding variables
    void AdvanceDeblocking(void);

    // Finalize decoding stuff, set specials flags
    void FinalizeDeblocking(void);

    // Deblocking of I-picture macroblocks
    void DeblockIMbVert(void);
    void DeblockIMbHorz(void);

    // Deblocking of P-picture macroblocks
    void DeblockPBMbVert(void);
    void DeblockPBMbHorz(void);

    // get Strengt for blocks ih MB for P picture
    void GetStrengthsForPMbVert(void);
    void GetStrengthsForPMbHorz(void);

    // Get strength for blocks of inter MB for B picture
    void GetStrengthsForBMbVert(void);
    void GetStrengthsForBMbHorz(void);

    AVS_DEBLOCKING_CONTEXT m_debCtx;                            // (AVS_DEBLOCKING_CONTEXT) deblocking process parameters

    Ipp32s alpha_c_offset;                                      // (Ipp32s) alpha value offset
    Ipp32s beta_offset;                                         // (Ipp32s) beta value offset
    Ipp8u m_alpha[4];                                           // (Ipp8u []) alpha values
    Ipp8u m_beta[4];                                            // (Ipp8u []) beta values
    Ipp8u m_thresholds[4];                                      // (Ipp8u []) thresholds values
    Ipp8u m_strengths[4];                                       // (Ipp8u []) strengths values
    IppiFilterDeblock_8u m_lumaDebInfo;                         // (IppiFilterDeblock_8u) luminance deblocking variables
    IppiFilterDeblock_8u m_chromaDebInfo[2];                    // (IppiFilterDeblock_8u []) chrominance deblocking variables

    //
    // common members
    //
    Ipp32s MbIndex;                                             // (Ipp32s) index of being decoded macroblock
    const AVS_MB_INFO *m_pMbInfo;                               // (const AVS_MB_INFO *) current macroblock's properties
    const AVS_MB_INFO *m_pMbInfoLeft;                           // (const AVS_MB_INFO *) left macroblock's properties
    const AVS_MB_INFO *m_pMbInfoTop;                            // (const AVS_MB_INFO *) top macroblock's properties*/

};

inline
void AVSDeblocker::SetDeblockingContext(AVS_DEBLOCKING_CONTEXT &debCtx)
{
    m_debCtx = debCtx;

} // void AVSDeblocker::SetDeblockingContext(AVS_DEBLOCKING_CONTEXT &debCtx)

inline
AVS_DEBLOCKING_CONTEXT & AVSDeblocker::GetDeblockingContext(void)
{
    return m_debCtx;

} // AVS_DEBLOCKING_CONTEXT & AVSDeblocker::GetDeblockingContext(void)

template <class dst_t> inline
dst_t ICLIP(dst_t valMin, dst_t valMax, Ipp32s Val)
{
    if (valMin > Val)
        return valMin;
    else if (valMax < Val)
        return valMax;

    return (dst_t) Val;

} // dst_t ICLIP(dst_t Min, dst_t Max, int Val)

} // namespace UMC


#endif // __UMC_AVS_DEC_DEBLOCKER_H
